package com.anyisn.anyflickr.shell.view
{
	import flash.events.Event;
	
	import mx.events.CloseEvent;
	
	import com.anyisn.anyflickr.shell.ShellFacade;
	import com.anyisn.anyflickr.shell.model.SettingsProxy;
	import com.anyisn.anyflickr.shell.model.vo.SettingsVO;
	import com.anyisn.anyflickr.shell.view.components.popup.SettingsTW;
	import com.anyisn.puremvc.as3.multicore.patterns.mediator.AbstractPopupMediator;

	public class SettingsTWMediator extends AbstractPopupMediator
	{
		public static const NAME:String = "SettingsTWMediator";
		
		public function SettingsTWMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		
			settingsTW.addEventListener(CloseEvent.CLOSE, close);
			settingsTW.addEventListener(SettingsTW.SAVE, save);
		}
		
		override public function onRegister() : void {
			var proxy:SettingsProxy = facade.retrieveProxy(SettingsProxy.NAME) as SettingsProxy;
			var vo:SettingsVO = new SettingsVO();
			vo.tilePerpage = proxy.tilePerpage;
			vo.slidePerpage = proxy.slidePerpage;
			vo.slideDelay = proxy.slideDelay;
			vo.singleDownloadPath = proxy.singleDownloadPath;
			vo.batchDownloadPath = proxy.batchDownloadPath;
			settingsTW.settingsVO = vo;
		}
		
		private function close(e:Event = null):void {
			closePopUpWindow(settingsTW, NAME);
		}
		
		private function save(e:Event):void {
			sendNotification(ShellFacade.SETTINGS_SAVE, settingsTW.settingsVO);
			close();
		}
		
		private function get settingsTW():SettingsTW {
			return viewComponent as SettingsTW;
		}
	}
}